package com.example.rentalclearing.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.rentalclearing.entity.RentalPaymentSchedule;
import com.example.rentalclearing.mapper.RentalPaymentScheduleMapper;
import com.example.rentalclearing.service.IRentalPaymentScheduleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 * 租金计划表 服务实现类
 * </p>
 *
 * @author sjf
 * @since 2025-10-17
 */
@Slf4j
@Service
public class RentalPaymentScheduleServiceImpl extends ServiceImpl<RentalPaymentScheduleMapper, RentalPaymentSchedule> implements IRentalPaymentScheduleService {

    /**
     * 根据收款日期查询未全部核销的租金计划
     *
     * @param date
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public List<RentalPaymentSchedule> selectUnwrittenByDateBefore(LocalDate date, int pageNum, int pageSize) {
        return lambdaQuery()
                .le(RentalPaymentSchedule::getReceivableDate, date)
                .ne(RentalPaymentSchedule::getWriteOffStatus, "fully_written")
                .orderByAsc(RentalPaymentSchedule::getReceivableDate)
                .page(new Page<>(pageNum, pageSize))
                .getRecords();
    }

}
